<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <!-- <script src="../../node_modules/lodash/cloneDeep.js"></script> -->
    <title>DeepClone Api</title>
</head>
<body>
    <script>
        // JSON.parse + JSON.stringify
        // var obj = {name: 1};
        // var obj2 = JSON.parse(JSON.stringify(obj));
        // obj2.name = 2;
        // console.log(obj, obj2)
        var obj = {
            name: 1,
            array: [1,2,3,4,5],
            fn: function(){
                console.log(1);
            }
        }
        // 由于 JSON.stringify的过程中， 任意函数 Symbol null undefined都会被忽略 所以 这种拷贝方式有缺陷
        // var obj2 = JSON.parse(JSON.stringify(obj));
        // // console.log(JSON.stringify(obj))
        // obj2.array[0] = 3;
        // console.log(obj2);
        var obj2 = Object.assign({}, obj); // 如果当前拷贝的属性值都为基本数据类型 则可以用 涉及到引用数据类型就不好使了
        var obj3 = {...obj};
        // obj2.array[0] = 5;
        obj2.name = 3;
        console.log(obj, obj2)
        // lodash deepClone
        // console.log(cloneDeep(obj));
    </script>
</body>
</html>